package com.sentiment.database.bean;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.bson.BsonDocument;
import org.bson.BsonDocumentWrapper;
import org.bson.Document;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.types.ObjectId;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sentiment.database.dbUtil.DbUtil;
import com.sentiment.nlpalgo.bean.Keywords;

@SuppressWarnings("serial")
public class DailyReport extends Document {
	public DailyReport(Boolean published){
		append("status", published);
	}
	public DailyReport(ObjectId id){
		append("_id", id);
	}
	public DailyReport() {
		// TODO Auto-generated constructor stub
	}
	// private ObjectId _id;
	// //每日舆情的发布时间
	// private String date;
	// //标题
	// private String title;
	//
	// //正文内容
	// private List<String> text;
	// //微博意见
	// private List<String> weiboOpinion_id;
	// //论坛意见
	// private List<String> forumOpinion_id;
	//
	// //媒体占比
	// private Map<String,Double> mediaRatio;
	//
	// //站点/发布时间
	// private Map<String, Date> releaseTimeRatio;
	//
	// //状态位，已发布为true，未发布为false
	// private Boolean status;
	// //记录文章中的关键词
	// private List<String> keywords;

	public void setUpdate(String method, DailyReport n) {
		append(method, n);
	}
	
	public Map<String, Double> getMediaRatio() {
		return (Map<String, Double>) get("mediaRatio");
	}

	public void setMediaRatio(Map<String, Double> mediaRatio) {
		append("mediaRatio", mediaRatio);
	}

	public Map<String, Date> getReleaseTimeRatio() {
		return (Map<String, Date>) get("releaseTimeRatio");
	}

	public void setReleaseTimeRatio(Map<String, Date> releaseTimeRatio) {
		append("releaseTimeRatio", releaseTimeRatio);
	}

	public ObjectId get_id() {
		return getObjectId("_id");
	}

	public void set_id(ObjectId _id) {
		append("_id", _id);
	}

	public List<CrawlInfo> getOpinion() {
		if (this.getWeiboOpinion_id() == null) {
			return null;
		}
		List<CrawlInfo> infolist = new ArrayList<>();
		DbUtil db = new DbUtil();
		db.openConnection(CrawlInfo.dbName, CrawlInfo.collection);
		for (int i = 0; i < this.getWeiboOpinion_id().size(); i++) {
			Document t = db.query(this.getWeiboOpinion_id().get(i));
			// 只传了Document中的发言人、内容、id字段
			infolist.add(new CrawlInfo(t, 3));
		}
		db.closeConnection();

		return infolist;
	}

	public String getDate() {
		return getString("date");
	}

	public void setDate(String date) {
		append("date", date);
	}

	public String getTitle() {
		return getString("title");
	}

	public void setTitle(String title) {
		append("title", title);
	}

	public List<String> getText() {
		return (List<String>) get("text");
	}

	public void setText(List<String> text) {
		append("text", text);
	}

	public List<String> getWeiboOpinion_id() {
		return (List<String>) get("weiboOpinion_id");
	}

	public void setWeiboOpinion_id(List<String> weiboOpinion_id) {
		append("weiboOpinion_id", weiboOpinion_id);
	}

	@JsonIgnore
	public List<String> getForumOpinion_id() {
		return (List<String>) get("forumOpinion_id");
	}

	public void setForumOpinion_id(List<String> forumOpinion_id) {
		append("forumOpinion_id", forumOpinion_id);
	}

	public Boolean getStatus() {
		return getBoolean("status");
	}

	public void setStatus(Boolean status) {
		append("status", status);
	}

	public List<Keywords> getKeywords() {
		return (List<Keywords>) get("keywords");
	}

	public void setKeywords(List<Keywords> keywords) {
		append("keywords", keywords);
	}
	
	public Double getSentiment(){
		return  getDouble("sentiment");
	}
	
	public void setSentiment(double sentiment){
		append("sentiment", sentiment);
	}
	
	public ObjectId getBindHotspot(){
		return getObjectId("bindHotspot");
	}
	
	public void setBindHotspot(ObjectId id){
		append("bindHotspot", id);
	}
	
	public void setCrawlNews_id(List<ObjectId> id){
		append("crawlNews_id", id);
	}
	
	public List<ObjectId> getCrawlNews_id(){
		return (List<ObjectId>)get("crawlNews_id");
	}
	
	@Override
	public <TDocument> BsonDocument toBsonDocument(Class<TDocument> documentClass, CodecRegistry codecRegistry) {
		// TODO Auto-generated method stub
		return new BsonDocumentWrapper<DailyReport>(this, codecRegistry.get(DailyReport.class));
	}
}
